import random

from yysautomatic.log import get_logger
from yysautomatic.core.gui import gui

logger = get_logger(__name__)


def click_tiaozhan(event):
    """
    组队挑战
    :param event:
    :return:
    """
    event.source.click()


def click_jiesuan(event):
    """
    结算事件
    :param event:
    :return:
    """
    client_x, client_y, w, h = event.frame.client_rect
    direction = int(random.randint(1000, 2999) / 1000)
    logger.debug('结界突破挑战界面点击随机: %s, %s, %s, %s, %s', client_x, client_y, w, h, direction)
    border = 20
    if direction == 1:
        start_x = client_x + 700
        end_x = client_x + w - border
        start_y = client_y + 140
        end_y = client_y + h - border
    else:
        start_x = client_x + border
        end_x = client_x + 100
        start_y = client_y + 160
        end_y = client_y + h - 70
    x = random.randint(start_x, end_x)
    y = random.randint(start_y, end_y)
    hit_count = random.randint(3, 6)
    logger.debug('挑战成功界面点击: %d, %d, hit_count: %d', x, y, hit_count)
    gui.click(x, y, hit_count)
